Telegram Group & Telegram Channel
🖥 Необходимо определить делегат и реализовать метод

Итак, вот задание:
определить делегат bool CounterHashSetDelegate(int a) и реализовать метод int Function12(HashSet<int> intSet, CounterHashSetDelegate filter), который возвращает количество элементов из intSet, которые удовлетворяют условию filter.
public static  class 
{
public delegate bool CounterHashSetDelegate(int a);
public static int Function12(HashSet<int> intSet, CounterHashSetDelegate filter)
{

int count = 0;
foreach (int i in intSet)
{
if(filter(i))
count++;
}
return count;
}
}



Давайте сразу к сути, решение может выглядеть так:
public delegate bool CounterHashSetDelegate(int a);

class Program
{
static void Main(string[] args)
{
CounterHashSetDelegate d = IsEvenNum;

Console.WriteLine($"Количество четных элементов:{Function12(new HashSet<int> { 1, 2, 3, 4, 5 }, d)}");

d = IsGreaterThen;

Console.WriteLine($"Количество элементов > 2:{Function12(new HashSet<int> { 1, 2, 3, 4, 5 }, d)}");

Console.ReadKey();
}

public static bool IsEvenNum(int a)
{
return a % 2 == 0;// четное ли число например
}

public static bool IsGreaterThen(int a)
{
return a > 2;//больше ли например
}


public static int Function12(HashSet<int> intSet, CounterHashSetDelegate filter)
{

int count = 0;
foreach (int i in intSet)
{
if (filter(i))
{
count++;
}
}
return count;
}

}

Вот и все дела

@csharp_ci
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/csharp_1001_notes/439
Create:
Last Update:

🖥 Необходимо определить делегат и реализовать метод

Итак, вот задание:
определить делегат bool CounterHashSetDelegate(int a) и реализовать метод int Function12(HashSet<int> intSet, CounterHashSetDelegate filter), который возвращает количество элементов из intSet, которые удовлетворяют условию filter.

public static  class 
{
public delegate bool CounterHashSetDelegate(int a);
public static int Function12(HashSet<int> intSet, CounterHashSetDelegate filter)
{

int count = 0;
foreach (int i in intSet)
{
if(filter(i))
count++;
}
return count;
}
}



Давайте сразу к сути, решение может выглядеть так:
public delegate bool CounterHashSetDelegate(int a);

class Program
{
static void Main(string[] args)
{
CounterHashSetDelegate d = IsEvenNum;

Console.WriteLine($"Количество четных элементов:{Function12(new HashSet<int> { 1, 2, 3, 4, 5 }, d)}");

d = IsGreaterThen;

Console.WriteLine($"Количество элементов > 2:{Function12(new HashSet<int> { 1, 2, 3, 4, 5 }, d)}");

Console.ReadKey();
}

public static bool IsEvenNum(int a)
{
return a % 2 == 0;// четное ли число например
}

public static bool IsGreaterThen(int a)
{
return a > 2;//больше ли например
}


public static int Function12(HashSet<int> intSet, CounterHashSetDelegate filter)
{

int count = 0;
foreach (int i in intSet)
{
if (filter(i))
{
count++;
}
}
return count;
}

}

Вот и все дела

@csharp_ci

BY C# 1001 notes




Share with your friend now:
tg-me.com/csharp_1001_notes/439

View MORE
Open in Telegram


C 1001 notes Telegram | DID YOU KNOW?

Date: |

What is Telegram?

Telegram is a cloud-based instant messaging service that has been making rounds as a popular option for those who wish to keep their messages secure. Telegram boasts a collection of different features, but it’s best known for its ability to secure messages and media by encrypting them during transit; this prevents third-parties from snooping on messages easily. Let’s take a look at what Telegram can do and why you might want to use it.

Dump Scam in Leaked Telegram Chat

A leaked Telegram discussion by 50 so-called crypto influencers has exposed the extraordinary steps they take in order to profit on the back off unsuspecting defi investors. According to a leaked screenshot of the chat, an elaborate plan to defraud defi investors using the worthless “$Few” tokens had been hatched. $Few tokens would be airdropped to some of the influencers who in turn promoted these to unsuspecting followers on Twitter.

C 1001 notes from ye


Telegram C# 1001 notes
FROM USA